from cache.redis_util import getConnection
from dbse.mysql.db_mysql_insert import getDataBase

db = getDataBase('prod')
redis = getConnection('prod')

'''
导入redis stock:gn:{count}
'''
# 查询所有概念
query_sql = "select distinct t2.gn_code,t2.gn_url from stock_ths_gn_current_config t1 join stock_ths_gn t2 on t1.gn_code = t2.gn_code where t1.type > 0"
db = getDataBase('prod')
cursor = db.cursor()
cursor.execute(query_sql)
gns = cursor.fetchall()

for index,gn in enumerate(gns):
    redis.hsetnx(name=f'stock:gn:{index+1}',key="url",value=gn[1])
    redis.hsetnx(name=f'stock:gn:{index+1}',key="gn_code",value=gn[0])
